package org.amigo.online.consumer.advertisement.controller;
	
import org.amigo.online.consumer.advertisement.exception.AdvException;
import org.amigo.online.consumer.advertisement.feignService.AdvFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.amigo.online.common.base.controller.BaseConsumerController;
import com.amigo.online.common.core.response.Response;
import com.amigo.online.common.core.response.StatusCode;
import com.amigo.online.common.core.security.IgnoreSecurity;
import com.amigo.online.common.param.dto.adv.AdvClickDto;
import com.amigo.online.common.param.dto.adv.AdvHomeDto;
import com.amigo.online.common.param.dto.adv.AdvLookDto;
import com.amigo.online.common.param.dto.adv.AdvNearbyDto;
import com.amigo.online.common.param.dto.adv.AdvRecommendDto;
import com.amigo.online.common.param.dto.adv.AdvTantanDto;

/**
 * 
 * @version: V 1.0.0
 * @Description: （广告comsumer contoller 层） 
 * @author: zxy  QQ:1363320658
 * @date: 2018年12月3日 下午3:33:42  
 *
 */
@RestController
@RequestMapping(value = "/v1/adv", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class AdvController extends BaseConsumerController {
	
	@Autowired
	AdvFeignService advFeignService;
	/**
	 * 获取探探广告
	 * 
	 * @return
	 */
	@IgnoreSecurity
	@PostMapping(value = "/list/tantan")
	public ResponseEntity<Response> getTantanAdvSource(@RequestBody AdvTantanDto advTantanDto) {
		if (advTantanDto.getNumber() <= 0 || advTantanDto.getNumber() > 3) {
			throw new AdvException(StatusCode.BAD_REQUEST);
		}
		return advFeignService.getTantanAdvSource(advTantanDto);
	}

	/**
	 * 获取附近的人广告
	 * 
	 * @return
	 */
	@IgnoreSecurity
	@PostMapping(value = "/list/nearby")
	public ResponseEntity<Response> getNearbyAdvSource(@RequestBody AdvNearbyDto advNearbyDto) {
		if (advNearbyDto.getNumber() <= 0 || advNearbyDto.getNumber() > 3) {
			throw new AdvException(StatusCode.BAD_REQUEST);
		}
		return advFeignService.getNearbyAdvSource(advNearbyDto);
	} 
	

	/**
	 * 获取APP主页广告
	 * 
	 * @return
	 */
	@IgnoreSecurity
	@PostMapping(value = "/list/home")
	public ResponseEntity<Response> getHomeAdvSource(@RequestBody AdvHomeDto advHomeDto) {
		return advFeignService.getHomeAdvSource(advHomeDto);
	}

	/**
	 * 获取推荐视频广告
	 * 
	 * @return
	 */
	@IgnoreSecurity
	@PostMapping(value = "/list/recommended")
	public ResponseEntity<Response> getRecommendVideoAdvSource(@RequestBody AdvRecommendDto advRecommendDto) {
		if (advRecommendDto.getNumber() <= 0 || advRecommendDto.getNumber() > 3) {
			throw new AdvException(StatusCode.BAD_REQUEST);
		}
		return advFeignService.getRecommendVideoAdvSource(advRecommendDto);
	}

	/**
	 * 记录推荐视频广告观看记录
	 * 
	 * @return
	 */
	@IgnoreSecurity
	@PostMapping(value = "/look/recommended")
	public ResponseEntity<Response> recordLookRecommendVideoAdv(@RequestBody AdvLookDto advLookDto) {
		if (advLookDto.getAdvId() == null || advLookDto.getAdvId() <= 0) {
			throw new AdvException(StatusCode.BAD_REQUEST);
		}
		return advFeignService.recordLookRecommendVideoAdv(advLookDto);
	}

	/**
	 * 记录探探广告观看记录
	 * 
	 * @return
	 */
	@PostMapping(value = "/look/tantan")
	@IgnoreSecurity
	public ResponseEntity<Response> recordLookTantanAdv(@RequestBody AdvLookDto advLookDto) {
		if (advLookDto.getAdvId() == null || advLookDto.getAdvId() <= 0) {
			throw new AdvException(StatusCode.BAD_REQUEST);
		}
		return advFeignService.recordLookTantanAdv(advLookDto);
	}

	/**
	 * 记录附近的人广告观看记录
	 * 
	 * @return
	 */
	@IgnoreSecurity
	@PostMapping(value = "/look/nearby")
	public ResponseEntity<Response> recordLookNearbyAdv(@RequestBody AdvLookDto advLookDto) {
		if (advLookDto.getAdvId() == null || advLookDto.getAdvId() <= 0) {
			throw new AdvException(StatusCode.BAD_REQUEST);
		}
		return advFeignService.recordLookNearbyAdv(advLookDto);
	}

	/**
	 * 记录APP主页广告观看记录
	 * 
	 * @return
	 */
	@IgnoreSecurity
	@PostMapping(value = "/look/home")
	public ResponseEntity<Response> recordLookHomeAdv(@RequestBody AdvLookDto advLookDto) {
		if (advLookDto.getAdvId() == null || advLookDto.getAdvId() <= 0) {
			throw new AdvException(StatusCode.BAD_REQUEST);
		}
		return advFeignService.recordLookHomeAdv(advLookDto);
	}

	/**
	 * 记录推荐视频广告观看记录
	 * 
	 * @return
	 */
	@IgnoreSecurity
	@PostMapping(value = "/click/recommended")
	public ResponseEntity<Response> recordClickRecommendVideoAdv(@RequestBody AdvClickDto advClickDto) {
		if (advClickDto.getAdvId() == null || advClickDto.getAdvId() <= 0) {
			throw new AdvException(StatusCode.BAD_REQUEST);
		}
		return advFeignService.recordClickRecommendVideoAdv(advClickDto);
	}

	/**
	 * 记录探探广告观看记录
	 * 
	 * @return
	 */
	@PostMapping(value = "/click/tantan")
	@IgnoreSecurity
	public ResponseEntity<Response> recordClickTantanAdv(@RequestBody AdvClickDto advClickDto) {
		if (advClickDto.getAdvId() == null || advClickDto.getAdvId() <= 0) {
			throw new AdvException(StatusCode.BAD_REQUEST);
		}
		return advFeignService.recordClickTantanAdv(advClickDto);
	}

	/**
	 * 记录附近的人广告观看记录
	 * 
	 * @return
	 */
	@IgnoreSecurity
	@PostMapping(value = "/click/nearby")
	public ResponseEntity<Response> recordClickNearbyAdv(@RequestBody AdvClickDto advClickDto) {
		if (advClickDto.getAdvId() == null || advClickDto.getAdvId() <= 0) {
			throw new AdvException(StatusCode.BAD_REQUEST);
		}
		return advFeignService.recordClickNearbyAdv(advClickDto);
	}

	/**
	 * 记录APP主页广告观看记录
	 * 
	 * @return
	 */
	@IgnoreSecurity
	@PostMapping(value = "/click/home")
	public ResponseEntity<Response> recordClickHomeAdv(@RequestBody AdvClickDto advClickDto) {
		if (advClickDto.getAdvId() == null || advClickDto.getAdvId() <= 0) {
			throw new AdvException(StatusCode.BAD_REQUEST);
		}
		return advFeignService.recordClickHomeAdv(advClickDto);
	}
	
	
	//获得广告投放的地址列表
	@GetMapping(value="/areaInfo/{countryId}")
	public ResponseEntity<Response> getAdvAreaInfo(@PathVariable("countryId") Long countryId ){
		return advFeignService.getAdvAreaInfo(countryId);
	}
	
}
